<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        下达申请
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>项目信息</label>
                                    <input type="text" name="code" class="form-control" placeholder="请输入厂内编号或名称">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>需方</label>
                                    <input type="text" name="demander" class="form-control" placeholder="请输入材质">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>安装地点</label>
                                    <input type="text" name="address" class="form-control" placeholder="请输入品级">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>设计科室</label>
                                    <input type="text" name="designDepts" class="form-control" placeholder="请输入具体位置">
                                </div>

                                <div class="form-group" style="margin-right: 10px;margin-top: 5px;">
                                    <label>设计类别</label>
                                    <select name="projectClassify" class="form-control" style="width:200px;" id="eqmFkTypeEdit">
                                        <option value="" selected="selected">全部</option>
                                        <option  value="1">设计</option>
                                        <option  value="2">非设计</option>
                                    </select>
                                </div>

                                <div class="form-group" style="margin-right: 10px;">
                                    <label>任务状态</label>
                                    <input type="text" name="remark" class="form-control" placeholder="请输入使用部门">
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search" style="margin-top: 5px;">
                                    <!--<i class="fa fa-search"></i>-->
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" style="table-layout: fixed;word-break:break-all; word-wrap:break-word;"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<!--创建类型模态框-->
<div class="modal fade" id="modal-edit-project">
    <div class="modal-dialog" style="width:800px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">项目标记</h4>
            </div>
            <div class="modal-body" style="padding: 0px;">
                <form id="typeForm-edit" class="form-horizontal">
                    <div class="col-md-12" style="padding-top: 15px;">
                        <input type="hidden" name="id"/>
                        <input type="hidden" name="tid"/>
                        <input type="hidden" name="code"/>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">说明</label>
                           <div class="col-sm-8">
                               <textarea rows="3" class="form-control" id="remark" name="remark" placeholder="标记说明"></textarea>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-create-type">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

<div th:include="include :: footer"></div>
<script th:inline="javascript">
    /** 加载用户表格 */
    table = js.table.init({
    url: ctx + "taskApply/list",
    showColumns: false,
        showExport: false,
        pageSize:300,
    columns: [
    {
        title: '序号', field: 'id', width: '50',
        formatter: function (value, row, index, field) {
            var pageSize = table.bootstrapTable('getOptions').pageSize;
            var pageNumber = table.bootstrapTable('getOptions').pageNumber;
            return pageSize * (pageNumber - 1) + index + 1;
        }
    },

    { title: "项目编号", field: 'code'},
    { title: "项目名称", field: 'name'},
    { title: "需方", field: 'demander'},
    { title: "数量", field: 'num'},
    { title: "单位", field: 'unit'},
    { title: "安装地点", field: 'address'},
    { title: "设计部门", field: 'designDepts'},
    { title: "设计类别", field: 'projectClassify',
        formatter: function(value, row, index){
            if(value==1){
                return '设计';
            }else if(value==2){
                return '非设计';
            }else{
                return '';
            }
        }
    },
        { title: "立项时间", field: 'createTime1'},
        // { title: "下达状态", field: 'isAssigned',
        //     formatter: function(value, row, index){
        //         if(value==1){
        //             return '<span class="label label-info">已下达</span>';
        //         }else{
        //             return '';
        //         }
        //     }
        // },
    //     { title: "任务状态", field: 'isExpedited',
    //     formatter: function(value, row, index){
    //         if(value==1){
    //             return '<span class="label label-danger">加急</span>';
    //         }else{
    //             return '';
    //         }
    //     }
    // },
    { title: "说明", field: 'remark'},
    // { title: "备注", field: 'comment'},
    {
    title: "操作",
    width: '110',
    formatter: function (value, row, index) {
        var actions = [];

        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="editType(' + js.jsonStringify(row) + ')"> 编辑</a> ');

         actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)"  onclick="applyProject(' + row.id + ','+row.tid+')"> 申请</a> ');

        return actions.join('');
    }
    }
    ]
    });

    /**
     * 点击申请，执行事件
     * @param kbid
     * @param rwid
     */
    function applyProject(kbid,rwid) {
        //alert(rwid);
        if(rwid!=null && rwid!=''){
            //执行修改,申请的状态
            js.post({
                url: ctx + "taskApply/upd",
                data: {tid:rwid},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        }else{
            //直接执行添加
            //alert('执行添加');
        }
    }
    /**
     * 单选 复选按钮的样式
     */
    // $(document).ready(function(e) {
    //     $('input').lc_switch();
    //     $('body').delegate('.lcs_check', 'lcs-statuschange', function() {
    //         var status = ($(this).is(':checked')) ? 'checked' : 'unchecked';
    //         console.log('field changed status: '+ status );
    //     });
    //     $('body').delegate('.lcs_check', 'lcs-on', function() {
    //         $("#isExpedited").val(1);
    //         console.log('field is checked');
    //     });
    //     $('body').delegate('.lcs_check', 'lcs-off', function() {
    //         $("#isExpedited").val(0);
    //         console.log('field is unchecked');
    //     });
    // });

    /**
    *编辑类型
     */
    function editType(row){
        $("#typeForm-edit").fillData(row);
        js.modal.open("modal-edit-project");
    }

    /** 创建类型 */
    $("#btn-create-type").click(function () {
        if($("#remark").val().trim().length==0){
            js.modal.closeLoading();
            return;
        }
        js.post({
            url: ctx + "taskApply/apply",
            data: $("#typeForm-edit").serialize(),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("modal-edit-project");
                } else {
                    js.modal.warning(result.msg);
                }
                js.modal.closeLoading();
            }
        });
    });

    /**
     * 表格搜索
     */
    $("#btn-search").click(function () {
        js.table.search(table);
    });
</script>